package com.andong.controller;

import com.andong.utils.AliOSSUtils;
import com.andong.domain.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

@Slf4j
@RestController
public class FileController {

    @Resource
    private AliOSSUtils aliOSSUtils;

    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws IOException {
        //调用阿里云OSS工具类进行文件上传
        String url = aliOSSUtils.upload(file);
        return Result.success(url);
    }

    @DeleteMapping("/delete")
    public Result delete(String url) throws IOException {
        aliOSSUtils.delete(url);
        return Result.success();
    }

    @GetMapping("/progress")
    public Result getProgress() {
        return Result.success(aliOSSUtils.getProgress());
    }
}
